package com.cq.hd.app.controller;

import com.cq.hd.app.biz.RedPacketStatisticsBiz;
import com.cq.hd.app.vo.RedPacketStatisticsVo;
import com.cq.hd.common.annotation.LoginUser;
import com.cq.hd.common.entity.AppLoginUser;
import com.cq.hd.common.entity.BusinessInfo;
import com.cq.hd.common.pagination.Page;
import com.cq.hd.common.response.Result;
import com.cq.hd.common.response.ResultGenerator;
import com.cq.hd.product.api.dto.RedPacketStatisticsDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.math.BigDecimal;

@RestController
@RequestMapping("/statistics/redPacket")
@Api(tags = "红包中心相关接口")
public class RedPacketStatisticsController {

    @Autowired
    private RedPacketStatisticsBiz redPacketStatisticsBiz;

    @ApiOperation(value = "红包成本")
    @GetMapping("/getTotalCost")
    public Result<BigDecimal> getRedPacketTotalCost(@ApiIgnore @LoginUser AppLoginUser appLoginUser) {
        Long businessId = 0L;
        BusinessInfo businessInfo = appLoginUser.getUserInfo().getBusinessInfo();
        if (businessInfo != null) {
            businessId = businessInfo.getId();
        }

        return ResultGenerator.success(redPacketStatisticsBiz.getRedPacketTotalCost(appLoginUser.getUserId(), businessId));
    }

    @ApiOperation(value = "红包明细列表")
    @ApiResponse(response = RedPacketStatisticsVo.class, code = 200, message = "接口返回对象参数")
    @GetMapping("/page")
    public Result<Page<RedPacketStatisticsVo>> pageRedPacketStatistics(RedPacketStatisticsDto redPacketStatisticsDto, @ApiIgnore @LoginUser AppLoginUser appLoginUser) {
        Long businessId = 0L;
        BusinessInfo businessInfo = appLoginUser.getUserInfo().getBusinessInfo();
        if (businessInfo != null) {
            businessId = businessInfo.getId();
        }

        redPacketStatisticsDto.setBusinessId(businessId);
        redPacketStatisticsDto.setUserId(appLoginUser.getUserId());
        return ResultGenerator.success(redPacketStatisticsBiz.pageRedPacketStatistics(redPacketStatisticsDto));
    }


}
